import { ref } from 'vue';

const times = ref(null) as any;

const a = ref(true);

// timerFun(ceShi, 1000)(); 调用方式

// 定时器
const timerFun = (f: any, time: any) => {
  return function backFun() {
    clearTimeout(times.value);

    times.value = setTimeout(function () {
      f();
      backFun();
    }, time);
  };
};

// 销毁
const destroyTime = () => {
  clearTimeout(times.value);

  a.value = true;
};

export { timerFun, destroyTime };
